package com.dsg.controller;

import com.dsg.entity.*;
import com.dsg.service.ServiceService;
import com.dsg.utils.Log;
import com.dsg.vo.PageResult;
import com.dsg.vo.SerDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class ServiceController {

    private String msg;
    @Resource
    private ServiceService serviceService;

    @GetMapping("/ser")
    public String ser(){
        return "ser/SerCreation";
    }
    @GetMapping("/serFP")
    public String serFP(){
        return "ser/SerAllocation";
    }
    @GetMapping("/serCl")
    public String serCl(){
        return "ser/SerProcessing";
    }
    @GetMapping("/serGd")
    public String serGd(){
        return "ser/SerArchiving";
    }
    @GetMapping("/serlist")
    @ResponseBody
    public PageResult list(Integer offset, Integer limit,SerDto serDto){
        return serviceService.seachPagination(offset,limit,serDto);
    }

    @GetMapping("/typelist")
    @ResponseBody
    public List<Servicetype> typelist(){
        return serviceService.seachType();
    }
    @GetMapping("/startlist")
    @ResponseBody
    public List<Fuwustart> startlist(){
        return  serviceService.seachStart();
    }
    //查询所有客户
    @GetMapping("/susNamelist")
    @ResponseBody
    public List<Customer> cusName(){
       return serviceService.seachcusName();
    }
    @GetMapping("/staYglist")
    @ResponseBody
    public List<Staff> staYg(){
        return serviceService.seachAllYg();
    }

    @GetMapping("/delService")
    @ResponseBody
    public String delService(Integer[] ids){
        try{
        serviceService.delService(ids);
            msg="删除成功！";
        }catch (Exception ex){
            msg="删除失败！";
            Log.logger.error(msg,ex);
        }
        return msg;
    }
    @GetMapping("/serupdate")
    @ResponseBody
    public String serUpdate(Service service){
        try {
        serviceService.update(service);
            msg="修改成功！";
        }catch (Exception ex){
            msg="修改失败！";
            Log.logger.error(msg,ex);
        }
        return msg;
    }

    @GetMapping("/addser")
    @ResponseBody
    public String add(Service service){
        try {
            serviceService.add(service);
            msg="添加成功~~";
        }catch (Exception ex){
            msg="添加失败···";
        }
        return msg;
    }
    @GetMapping("/xiugaiSta")
    @ResponseBody
    public int updateStart(int i){
       try {
           msg="提交成功！";
         serviceService.updateStart(i);
       }catch (Exception ex){
           msg="提交失败··";
       }
       return i;
    }
    @GetMapping("/FanKui")
    @ResponseBody
    public String updateFanKui(Integer[] ids){
      try {
        serviceService.updateFankui(ids);
          msg="归档成功！";
      }catch (Exception ex){
          msg="归档失败~~";
      }
      return msg;
    }
    @GetMapping("/updafenpei")
    @ResponseBody
    public String updafenpei(Service service){
        try{
        serviceService.updatefenpei(service);
            msg="已分配···";
        }catch (Exception ex){
            msg="分配失败！！！";
        }
        return msg;
    }
    @GetMapping("/updatechuli")
    @ResponseBody
    public String updatechuli(Service service){
        try{
        serviceService.updatechuli(service);
            msg="已成功处理！";
        }catch (Exception ex){
            msg="处理失败···";
        }
        return msg;
    }
    @GetMapping("/updatefankui")
    @ResponseBody
    public String updatefankui(Service service){
        try{
            serviceService.updatechuli(service);
            msg="反馈保存成功！";
        }catch (Exception ex){
            msg="反馈保存失败！";
        }
        return msg;
    }
}
